package com.quasar.hpatient.view.adapter;

import android.text.TextPaint;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.custommodel.BloodSugarTableItem;
import com.quasar.hpatient.model.custommodel.RemindMedicineTableItem;
import com.quasar.hpatient.model.custommodel.TemperatureTableItem;
import com.quasar.hpatient.utils.Spanny;

import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/10/26 0026
 * View:
 */

public class BloodSugarAdapter extends BaseMultiItemQuickAdapter<TemperatureTableItem, BaseViewHolder> {


    public BloodSugarAdapter(List<TemperatureTableItem> data) {
        super(data);
        addItemType(TemperatureTableItem.HEAD, R.layout.widget_test_show);
        addItemType(TemperatureTableItem.BODY, R.layout.widget_test_show);
    }

    @Override
    protected void convert(BaseViewHolder helper, TemperatureTableItem item) {
        Spanny spanny = new Spanny();
        switch (helper.getItemViewType()) {
            case RemindMedicineTableItem.HEAD:
                helper.setText(R.id.title,"时间");//检测时间
                helper.setText(R.id.msg, "项目");//检测时间
                if(item.getDailyitemDose()!=null){
                    StringBuffer stringBuffer=new StringBuffer();
                    stringBuffer.append(item.getDailyitemDose());
                    helper.setText(R.id.msgcheck,stringBuffer.toString());//检测时间
                }else{
                    helper.setText(R.id.msgcheck,"检测值");//检测时间
                }
                helper.setText(R.id.demo,"状态");//检测时间
                break;

            case RemindMedicineTableItem.BODY:
                helper.setText(R.id.title, item.getLogTime());//检测时间
                helper.setText(R.id.msg, item.getDailyitemName());//检测项
                helper.setText(R.id.msgcheck, item.getLogValue()+"");//检测值

                TextView demo=helper.getView(R.id.demo);
                TextPaint tp = demo.getPaint();
                if(item.getStats().equals("0")) {
                    spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                }else if(item.getStats().equals("1")){
                    spanny.append("高血糖", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }else{
                    spanny.append("危机血糖", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }
                demo.setText(spanny);
                break;

        }

        helper.addOnClickListener(R.id.msgcheck);
        helper.addOnLongClickListener(R.id.msgcheck);
    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }
}
